const { invoke, query, enrollAdmin, registerUser} = require('../tools/index.js');

async function testQuery() {
    console.log("-------------testQuery--------------")
    const data = {
        username: "user1",
        chaincodeId: "mychannel",
        fcn: "query", 
        args: ["1"]
    }
    await query(data, r => {
        console.log(r)
    }, msg => {
        console.log(msg)
    })
}

async function testInvoke() {
    console.log("-------------testInvoke--------------")
    const data = {
        username: "user1",
        chaincodeId: "mychannel",
        channelId: "mychannel",
        fcn: "insert",
        args: ["2", "name2", "address2"],
    }
    await invoke(data, r => {
        console.log(r)
    }, msg => {
        console.log(msg)
    })
}

async function enroll(org) {
    console.log("-------------enroll--------------")
    const options = {
        org: org
    }
    await enrollAdmin(options);
}

async function register(username, org) {
    console.log("-------------register--------------")
    const options = {
        username: username, 
        org: org
    }
    await registerUser(options);
}

(async function() {
    await enroll("1");
    await register("user1", "1")
    await testQuery();
    await testInvoke();
})()